package com.ruoyi.expand.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.expand.service.CountryInfoService;
import com.ruoyi.expand.entity.CountryInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 国家管理控制器
 * @author zhangjiabing
 * @date 2021/8/01 17:37
 */
@Controller
@RequestMapping("/expand/countryInfo")
public class CountryInfoController extends BaseController {

    private String prefix = "expand/countryInfo";


    /**
     * 国家管理service接口
     */
    @Autowired
    private CountryInfoService countryService;


    /**
     * 列表页面
     * @return
     */
    @GetMapping()
    public String list()
    {
        return prefix + "/countryInfoList";
    }



    /**
     * 新增国家
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/countryInfoForm";
    }

    /**
     * 新增保存国家
     */
    @RequiresPermissions("countryeInfo:job:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated CountryInfo countryInfo)
    {
        AjaxResult ajaxResult= countryService.saveBPrivateRoom(countryInfo);
        return ajaxResult;
    }

    /**
     * 修改国家页面
     */
    @GetMapping("/edit/{bPrivateRoomId}")
    public String edit(@PathVariable("bPrivateRoomId") String bPrivateRoomId, ModelMap mmap)
    {
        mmap.put("countryInfo", countryService.selectJobById(bPrivateRoomId));
        return prefix + "/countryInfoEdit";
    }

    /**
     * 国家信息更新
     * @param countryInfo
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@Validated CountryInfo countryInfo)
    {
        AjaxResult ajaxResult= countryService.saveBPrivateRoom(countryInfo);
        return  ajaxResult;
    }


    /**
     * 数据删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        countryService.deleteBPrivateRoomByIds(ids);
        return success();
    }



    /**
     * 分页数据查询
     * @param countryInfo
     * @return
     */
    @PostMapping("/listPage")
    @ResponseBody
    public Object listPage(CountryInfo countryInfo,Integer pageNum,Integer pageSize)
    {
        TableDataInfo list = countryService.listPage(countryInfo,pageNum,pageSize);
        return list;
    }


    @Log(title = "国家信息管理管理", businessType = BusinessType.EXPORT)
    //@RequiresPermissions("system:role:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CountryInfo countryInfo)
    {
        List<CountryInfo> list = countryService.selectCountryList(countryInfo);
        ExcelUtil<CountryInfo> util = new ExcelUtil<CountryInfo>(CountryInfo.class);
        return util.exportExcel(list, "角色数据");
    }


}
